import tbgeo, tbgeoconst
from tbgeo import coordinates, position

def main():
    map = tbgeo.Map()
    d = 'Pulkovo 1942 POL'#tbgeoconst.DATUM_WGS_84
    map.setDatum(d)
    
    p = tbgeoconst.PROJ_LATLON
    map.setProjection(p)
    map.setWidth(3377)
    map.setHeight(1789)
    
    map.addCalibrationPoint1(20.204211, 52.447473, 0, 0)
    map.addCalibrationPoint1(20.890411, 52.447407, 3393, 0)
    map.addCalibrationPoint1(20.888823, 52.199841, 3393, 2017)
    map.addCalibrationPoint1(20.206442, 52.199918, 0, 2017)
    
    c = tbgeo.Calibration()
    if not c.register(map):
        print c.getError()
        return
    test = coordinates(52.2, 20.5)
    print 'input>', test.lat, test.lon
    pos = c.getPosition(test)
    print pos.x, pos.y  
    coords = c.getCoordinates(pos)
    print coords.lat, coords.lon      
    pos = position(1450, 2023)
    print 'input>', pos.x, pos.y
    coords = c.getCoordinates(pos)
    print coords.lat, coords.lon
    pos = c.getPosition(coords)
    print pos.x, pos.y   

if __name__ == '__main__':    
    main()
